import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import {getUserInfo} from "@/utils/auth";


/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/enterprise_login',
    component: () => import('@/views/enterprise_login/index'),
    hidden: true
  },
  {
    path: '/enterprise_register',
    component: () => import('@/views/enterprise_register/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  //首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: {title: '首页', icon: 'dashboard'}
      }
    ]
  },
  //账户信息
  {
    path: '/person/userinfo',
    component: Layout,
    children: [
      {
        path: '/person/userinfo',
        component: () => import('@/views/person/userinfo'),
        meta: { title: '用户信息', icon: 'user'}
      }
    ]
  },
  //个人用户-我发布的问卷
  {
    path: '/person/ipublish',
    component: Layout,
    children: [
      {
        path: '/person/ipublish',
        component: () => import('@/views/person/ipublish'),
        meta: { title: '我发布的问卷', icon: 'el-icon-notebook-2' }
      }
    ]
  },
  //个人用户-新建问卷
  {
    path: '/person/newform',
    component: Layout,
    children: [
      {
        path: '/person/newform',
        component: () => import('@/views/person/newform'),
        meta: { title: '新建问卷', icon: 'el-icon-edit-outline' }
      }
    ]
  },
  //个人用户-我收藏的模板
  {
    path: '/person/model',
    component: Layout,
    children: [
      {
        path: '/person/model',
        component: () => import('@/views/person/model'),
        meta: { title: '我收藏的模板', icon: 'el-icon-star-on' }
      }
    ]
  },
  //个人用户-编辑问卷
  {
    path: '/person/edit',
    component: Layout,
    hidden:true,
    children: [
      {
        path: '/person/edit',
        component: () => import('@/views/person/edit'),
        meta: { title: '编辑问卷'}
      }
    ]
  },
  //个人用户-填写问卷
  {
    path: '/person/write',
    component: Layout,
    hidden:true,
    children: [
      {
        path: '/person/write',
        component: () => import('@/views/person/write'),
        meta: { title: '填写问卷'}
      }
    ]
  },
  //个人用户-表单汇总
  {
    path: '/person/result',
    component: Layout,
    hidden:true,
    children: [
      {
        path: '/person/result',
        component: () => import('@/views/person/result'),
        meta: { title: '表单汇总'}
      }
    ]
  },
//企业
{
  path: '/enterprise',
  component: Layout,
  meta: {title: '企业工作', icon: 'el-icon-office-building'},
  children: [
    {
      path: '/enterprise/bussiness',
      meta: {title: '业务管理', icon: 'el-icon-menu'},
      component: () => import('@/views/enterprise/bussiness'),
    },
    {
      path: '/enterprise/flowctr',
      meta: {title: '流程管理', icon: 'el-icon-s-claim'},
      component: () => import('@/views/enterprise/flowctr'),
    },
    {
      path: '/enterprise/waittodo',
      meta: {title: '代办流程', icon: 'el-icon-s-check'},
      component: () => import('@/views/enterprise/waittodo'),
    },
    {
      path: '/enterprise/myapply',
      meta: {title: '我的申请', icon: 'el-icon-tickets'},
      component: () => import('@/views/enterprise/myapply'),
    },
    {
      path: '/enterprise/departmentctr',
      meta: {title: '部门管理', icon: 'el-icon-coin'},
      component: () => import('@/views/enterprise/departmentctr'),
    },
    {
      path: '/enterprise/rolectr',
      meta: {title: '角色管理', icon: 'el-icon-s-custom'},
      component: () => import('@/views/enterprise/rolectr'),
    },
    {
      path: '/enterprise/permissionctr',
      meta: {title: '权限管理', icon: 'el-icon-view'},
      component: () => import('@/views/enterprise/permissionctr'),
    },
  ]
},
//测试页
{
  path: '/test',
  component: Layout,
  meta: {title: '测试页', icon: 'el-icon-stopwatch'},
  children: [
    {
      path: '/test/zhangheng',
      meta: {title: '张恒'},
      component: () => import('@/views/test/zhangheng'),
    },
    {
      path: '/test/libin',
      meta: {title: '李彬'},
      component: () => import('@/views/test/libin'),
    },
    {
      path: '/test/liuqi',
      meta: {title: '刘琪'},
      component: () => import('@/views/test/liuqi'),
    },
  ]
},

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}


export default router
